/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package calcul;

import java.util.Observable;
import modele.SetParams;
import vue.ObjetEchange;

/**
 * Calcule en mesurant le temps d'execution.
 * Le calcul tourne sur un thread a part (lance a chaque clic sur le bouton), 
 * distinct du thread de la GUI. Contient du code (mesurant les perfs) commun aux 
 * implementations single-thread et multi-thread.
 * @see MonteCarloSingle
 * @see MonteCarloMulti
 * @author Jo
 */
public abstract class MonteCarloAbstract extends Observable implements Runnable {
    
    /**
     * Donnees.
     */
    double S, X, r, T, b, v;
    int nSteps, nSimulations;
    
    /**
     * Resultat.
     */
    double res=0;
    
    /**
     * Duree.
     */
    protected long duree_calcul=0;
    
    
    //nSteps =168
    //S=40, X=50, r=0.06, T=0.5, b=0.1, v=0.45;

    public MonteCarloAbstract(double S, double X, double r, double T, double b, double v, int nSteps, int nSimulations) {
        this.S = S;
        this.X = X;
        this.r = r;
        this.T = T;
        this.b = b;
        this.v = v;
        this.nSteps = nSteps;
        
        this.nSimulations = nSimulations;
        
        System.out.println("constructeur parametres = " + S + " " + X + " " + r + " " + T + " " + b + " " + v + " " + nSteps);
    }
    
    
    
    /**
     * 
     */
    @Override
    public void run() {
        long debut = System.currentTimeMillis();
        
        res = MonteCarloStandardOption("c", S, X, T, r, b, v, nSteps, nSimulations);
        
        long fin = System.currentTimeMillis();
        duree_calcul = fin-debut;
        
        setChanged();
        notifyObservers(new ObjetEchange(res, true, 100, duree_calcul));
        //System.out.println("Resultat : " + res + "$");
        //System.out.println("Duree de calcul : " + (fin-debut) + "ms");
        
        SetParams p = new SetParams(S, X, T, r, b, v, nSteps);
        String s = (this instanceof MonteCarloSingle)? "single" : "multi" ;
        Fichiers_log.ajouterAuFichierLog(duree_calcul + ";" + p.toString() +";"+ s , Fichiers_log.Benchmark.SINGLE_MULTI);
    }
    
    abstract double MonteCarloStandardOption ( String CallPutFlag, double S, double X, double T, 
            double r, double b, double v, int nSteps, int nSimulations);
}
